<template>
	<div>
		<ul class="aui-list aui-form-list aui-margin-b-15">
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">标签</div>
					<!-- <div class="aui-list-item-input aui-list-item-arrow">
						<p id="label">选择"家、公司"标签</p>
					</div> -->
					<div style="width: 100%" class="address-tab-box addressText">
						<label><input class="aui-radio" type="radio" name="address-tab" :checked="label=='家庭'" @click.stop="getLabel(0)"><span class="labelMargin">家庭</span></label>&nbsp;&nbsp;
						<label><input class="aui-radio" type="radio" name="address-tab" :checked="label=='公司'" @click.stop="getLabel(1)"><span class="labelMargin">公司</span></label>&nbsp;&nbsp;
						<label><input class="aui-radio" type="radio" name="address-tab" :checked="label=='其他'" @click.stop="getLabel(2)"><span class="labelMargin">其他</span></label>
					</div>
				</div>
			</li>
			<!--<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<label><input class="aui-checkbox" type="checkbox" name="demo1" ref='checkedBo' id="defaultAddress" :checked="defaultaddress=='默认'" @click.stop="setDefault">&nbsp;设为默认地址</label>
				</div>
			</li>-->
		</ul>
	</div>
</template>

<script>
	import {mapActions,mapMutations} from 'vuex';
	export default {
		props:{
			addFlag: {
				type: Boolean,
                default:true
			},
			getNowAddress: {
				type: Object,
				default: {}
			}
//			item: {
//              type: Object,
//              default:()=>{
//              	return {}
//              }
//          },
//          userInfomation: {
//          	type: Object,
//              default: ()=>{
//              	return {}
//              }
//          },
//          getstatusBtn: {
//          	type: Function,
//              default: () => {}
//          }
		},
		data() {
			return {
				nowAddress:{},
				defaultaddress:null,
				label:null
			}
		},
		watch:{
			defaultaddress(nvalue,ovalue){
				let nowAddressSinger = {};
				if(nvalue == '默认'){
					nowAddressSinger.defaultaddress = '1';
				}else if(nvalue == '非默认'){
					nowAddressSinger.defaultaddress = '0';
				}
				this.setNowAddressMutationSinger(nowAddressSinger);
//				console.log('defaultaddress',nowAddressSinger.defaultaddress);
			},
			label(nvalue,ovalue){
				let nowAddressSinger = {};
				if(nvalue == '家庭'){
					nowAddressSinger.label = '0';
				}else if(nvalue == '公司'){
					nowAddressSinger.label = '1';
				}else if(nvalue == '其他'){
					nowAddressSinger.label = '2';
				}
//				nowAddressSinger.receivername = nvalue;
				this.setNowAddressMutationSinger(nowAddressSinger);
//				console.log('label',nowAddressSinger.label);
			},
		},
		methods:{
			...mapMutations('zx',[
				"setNowAddressMutationSinger"
			]),
			getLabel(num){
				if(num == 0){
					this.label = '家庭';
				}else if(num == 1){
					this.label = '公司';
				}else if(num == 2){
					this.label = '其他';
				}
			},
			setDefault(){
				if(this.$refs.checkedBo.checked){
					this.defaultaddress = '默认';
				}else{
					this.defaultaddress = '非默认';
				}
			}
		},
		created(){
			console.log(this.addFlag,'是否是新增');
			console.log(this.getNowAddress,'当前地址info ');
			if(!this.addFlag){
				this.label = this.getNowAddress.label;
				if(this.label == '0'){
					this.label = '家庭';
				}else if(this.label == '1'){
					this.label = '公司';
				}else if(this.label == '2'){
					this.label = '其他';
				}
//				console.log(this.label,'当前地址infolabel');
				this.defaultaddress = this.getNowAddress.defaultaddress;
				if(this.defaultaddress == '1'){
					this.defaultaddress = '默认';
				}else if(this.defaultaddress == '0'){
					this.defaultaddress = '非默认';
				}
			}else if(this.addFlag){
				this.label = '家庭';
				this.defaultaddress = '默认';
			}
			
		}
	}
</script>

<style scoped="scoped">
	.addressText{
		text-align: left;
	}
	.labelMargin{
		margin-left: 7px;
	}
</style>